<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
            width: 100px;
            height: 100px;
        }

        .box {
            width: 500px;
            height: 103px;
            margin: 20px auto;
        }
    </style>
</head>

<body>
    <div class="box">
        <img src="images/1.jpg" alt="">
        <img src="images/2.jpg" alt="">
        <img src="images/3.jpg" alt="">
        <img src="images/4.jpg" alt="">
    </div>
    <script>
        var imgs = document.querySelectorAll('img');
        // var bd = document.querySelector('body')

        for (var i = 0; i < imgs.length; i++) {
            console.log(i);
            console.log(imgs[i].src);
            
            imgs[i].onclick = function () {
                var src = this.src;
                document.body.style.backgroundImage = 'url(' + src + ')';
            }
        }
    </script>
</body>

</html>